package com.lenin.omena.client;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.lenin.omena.client.event.SaveUserEvent;
import com.lenin.omena.shared.domain.Produce;
import com.lenin.omena.shared.domain.Site;
import com.lenin.omena.shared.domain.User;

public class AddProduceRow {
	
	
	private TextBox produceNameField;
	
	private TextBox produceAmountField;
	
	private TextBox producePriceField;
	
	private Button addButton;
	
	
	public AddProduceRow() {
		
		produceNameField = new TextBox();
		produceNameField.setWidth("100px");
		produceNameField.setMaxLength(18);
		
		produceAmountField = new TextBox();
		produceAmountField.setWidth("50px");
		produceAmountField.setMaxLength(12);
		
		producePriceField = new TextBox();
		producePriceField.setWidth("50px");
		producePriceField.setMaxLength(16);
		
		addButton = new Button("Lisää");
		
		addButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				addProduce();
			}
		});
		
		
	}

	
	public void clearFields() {
		
		produceNameField.setText("");
		produceAmountField.setText("");
		producePriceField.setText("");
	
	}
	
	public TextBox getProduceNameField() {
		return produceNameField;
	}


	public TextBox getProduceAmountField() {
		return produceAmountField;
	}


	public TextBox getProducePriceField() {
		return producePriceField;
	}


	public Button getAddButton() {
		return addButton;
	}


	public void addProduce() {
		
		Produce p = new Produce();
		p.setName(produceNameField.getText());
		p.setAmount(produceAmountField.getText());
		p.setPrice(producePriceField.getText());
		
		AppleMarket.doAddProduce(AppleMarket.getUserContext().getUser(), p);
		
	}

}
